package com.chendongyang.www.dao;
import com.chendongyang.www.po.apprise1;
import com.mysql.cj.jdbc.Driver;

import java.sql.*;
import java.util.ArrayList;

public class apprises {
    public ArrayList<String> select() throws SQLException {
        ArrayList<String> list=new ArrayList<>();
            DriverManager.registerDriver(new Driver());
            Connection root=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle","root","123456");
            String sql="select 充电口 from  charging;";
            PreparedStatement preparedStatement = root.prepareStatement(sql);
            ResultSet resultSet=preparedStatement.executeQuery();
            while(resultSet.next()){
                list.add(resultSet.getString(1));
            }
            root.close();
            preparedStatement.close();
            resultSet.close();
            return list;
    }
    public  int insert(String chargs,String comment,String id) throws SQLException {
        //客户对充电口进行选择充电；
            DriverManager.registerDriver(new Driver());
        Connection root = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle", "root", "123456");
        String sql="insert 充电站评价 values(?,?,?)";
        PreparedStatement preparedStatement = root.prepareStatement(sql);
        preparedStatement.setString(1,chargs);
        preparedStatement.setString(2,id);
        preparedStatement.setString(3,comment);
        int line =0;
        line = preparedStatement.executeUpdate();
        root.close();
        preparedStatement.close();
        return line;
    }
    public ArrayList<apprise1> select1() throws SQLException {
        ArrayList<apprise1> list=new ArrayList<>();
        DriverManager.registerDriver(new Driver());
        Connection root=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lle","root","123456");
        String sql="select * from  充电站评价;";
        PreparedStatement preparedStatement = root.prepareStatement(sql);
        ResultSet resultSet=preparedStatement.executeQuery();
        while(resultSet.next()){
            apprise1 test=new apprise1();
            test.setCharges(resultSet.getString(1));
            test.setComment(resultSet.getString(3));
            list.add(test);
        }
        root.close();
        preparedStatement.close();
        resultSet.close();
        return list;
    }
}
